﻿'========================================================================
'功能:變更申請MVPN
'作者:
'日期:
'========================================================================
Imports System.Data
Imports com.auo.flower.remote
Partial Class WebForm_SysParam_ChangeApply
    Inherits BasePage
    Protected FormKind As String = "AUO.FORM.439"
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            hiUID.Value = ActualUID
            hidbName.Value = dbName

            Dim uBBL As OAMS.BBL.UsersBBL = New OAMS.BBL.UsersBBL()
            Dim dt As DataTable = uBBL.GetUsers(hiUID.Value, hidbName.Value)
            txtApplicant.Text = dt.Rows(0)("UserID").ToString()
            txtApplyDate.Text = Date.Today.ToString("yyyy/MM/dd")
            txtApplyExt.Text = dt.Rows(0)("Ext_No").ToString()
            txtApplyName.Text = dt.Rows(0)("UserName").ToString()
            txtFiller.Text = dt.Rows(0)("UserID").ToString()
            txtFillerExt.Text = dt.Rows(0)("Ext_No").ToString()
            txtFormNo.Text = "1"
            Wizard1.ActiveStepIndex = 0


        End If
    End Sub


    Protected Sub Wizard1_ActiveStepChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Wizard1.ActiveStepChanged
       
    End Sub

    Protected Sub Wizard1_FinishButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles Wizard1.FinishButtonClick
        If txtSerial.Text = "" Then
            ShowMessageForAjax(btnUserPhone, "電話號碼沒有選擇")
            e.Cancel = True
            Exit Sub
        End If
        If trMemo.Visible Then
            If txtMemo.Text.Trim = "" Then
                ShowMessageForAjax(btnUserPhone, "故障說明不可空白")
                e.Cancel = True
                Exit Sub
            End If
        End If

        ''先存到ApplyChg中
        Dim appDAO As Telecom.DAO.ApplyDAO = New Telecom.DAO.ApplyDAO(hidbName.Value)
        Dim chgApplyFormNo As String = appDAO.InsertMVPNChg(txtApplicant.Text, txtApplyName.Text, txtApplyExt.Text, txtFiller.Text, ActualUserName, txtFillerExt.Text, txtSerial.Text, txtPhoneNo.Text, ddlModiItem.SelectedValue, ddlSite.SelectedValue, txtPnpCodeNew.Text, txtMemo.Text)

        '送往FlowER
        Dim formNo As Integer
        '' Dim formMVPN As MVPN.Manager.FromMVPNRemote = New MVPN.Manager.FromMVPNRemote(Me)
        Dim objhelper As IRemotingFlowHelper = DirectCast(RemotingHelperCreator.CreateInstance(GetType(IRemotingFlowHelper)), IRemotingFlowHelper)
        formNo = objhelper.CreateNewForm(FormKind, ActualUID)


        appDAO.UpdateMVPNApproveChgFlowerFormNo(formNo.ToString, txtFormNo.Text)

        Dim objParas(2) As IParameter
        Dim dtOnSite As DataTable
        Dim oBBL As Telecom.BBL.OnSiteBBL = New Telecom.BBL.OnSiteBBL()
        dtOnSite = oBBL.GetOnSite("0", ddlSite.SelectedValue, hidbName.Value)
        Dim IT_Approve As String = ""
        Dim OnSiteUID As String = ""

        If dtOnSite.Rows.Count > 0 Then
            IT_Approve = dtOnSite.Rows(0)("IT_Approve").ToString
            OnSiteUID = dtOnSite.Rows(0)("OnSiteUID").ToString
        End If
        Dim dt As DataTable


        Dim ApproveLevel As String = "0"

        ''變更類別
        Dim modiBBl As Telecom.BBL.ModifyItemBLL = New Telecom.BBL.ModifyItemBLL
        dt = modiBBl.GetModifyItem_DataByKind(ddlSite.SelectedValue, ddlModiItem.SelectedValue, hidbName.Value)
        If dt.Rows.Count > 0 Then
            ApproveLevel = dt.Rows(0)("NeedApprove").ToString
        End If
        objParas(0) = New para("Approve_Flag", ApproveLevel) ''層級
        objParas(1) = New para("Approve_IT", IT_Approve) 'IT必要簽核人員
        objParas(2) = New para("Approve_OA", OnSiteUID) '駐廠

        objhelper.AddFlag(FormKind, formNo, objParas)
        objhelper.SendForm(FormKind, formNo, ActualUID)
        objhelper.ActiveForm(FormKind, formNo)

        Response.Redirect(System.Configuration.ConfigurationManager.AppSettings("ApplyReturnPath"))
    End Sub

    Protected Sub Wizard1_NextButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles Wizard1.NextButtonClick
        Dim appDAO As Telecom.DAO.ApplyDAO = New Telecom.DAO.ApplyDAO(hidbName.Value)
        Dim dt As DataTable
        If e.CurrentStepIndex = 0 Then

            dt = appDAO.GetChtMVPN(txtApplicant.Text)
            If dt.Rows.Count >= 1 Then
                ' PopupFormForAjax(Wizard1, "Serial,EmpNo,EmpName,UserPhone,UserIDNo,PnpCode,FirstPay", ("編號,工號,姓名,手機,證件號碼,簡碼,群首付費"), "MVPN_Apply", hidbName.Value, "1,4", txtSerial.ClientID & "," & txtPhoneNo.ClientID, "directories=no,location=no,menubar=no,toolbar=no,scrollbars=yes, width800 ,left=200")

            Else
                ShowMessageForAjax(Wizard1, "沒有申請過資料,無法異動")
                e.Cancel = True
            End If



        End If

        If e.CurrentStepIndex = 1 Then
            If txtSerial.Text = "" Then
                e.Cancel = True
                ShowMessageForAjax(Wizard1, "電話號碼沒有選擇")
                Exit Sub
            End If
            If ddlModiItem.SelectedValue = "" Then
                ShowMessageForAjax(btnUserPhone, "變更項目未選定")
                e.Cancel = True
                Exit Sub
            End If

            dt = appDAO.GetChtMVPNBySerial(txtSerial.Text)
            If dt.Rows.Count > 0 Then
                txtPhone1.Text = txtPhoneNo.Text
                txtUserType.Text = dt.Rows(0)("UserType").ToString()
                txtMVPNType.Text = dt.Rows(0)("MVPNType").ToString()
                txtEmpNo.Text = dt.Rows(0)("EmpNo").ToString()
                txtEmpName.Text = dt.Rows(0)("EmpName").ToString()
                txtIDNO.Text = dt.Rows(0)("UserIDNo").ToString()
                Try
                    txtApplyTime.Text = DateTime.Parse(dt.Rows(0)("ApplyTime").ToString()).ToString("yyyy/MM/dd HH:mm:ss")
                Catch ex As Exception
                    txtApplyTime.Text = ""
                End Try

                txtStatus.Text = dt.Rows(0)("Status").ToString()
                txtPNPCode.Text = dt.Rows(0)("PnpCode").ToString()
                txtFirstPay.Text = dt.Rows(0)("FirstPay").ToString()
            Else


            End If

        End If



    End Sub

    Protected Sub ddlSite_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlSite.SelectedIndexChanged
        ddlModiItem.DataBind()
    End Sub

    Protected Sub btnUserPhone_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUserPhone.Click
        Dim appDAO As Telecom.DAO.ApplyDAO = New Telecom.DAO.ApplyDAO(hidbName.Value)
        If ddlModiItem.SelectedValue = "" Then
            ShowMessageForAjax(btnUserPhone, "變更項目請選擇")
            Exit Sub
        End If

        Try
            Dim kind As String
            Dim modiAdo As Telecom.DAO.ModifyItemDAO = New Telecom.DAO.ModifyItemDAO(hidbName.Value)

            kind = modiAdo.GetModifyItem_Data(ddlSite.SelectedValue, ddlModiItem.SelectedValue).Rows(0)("kind").ToString()
            Dim dt As DataTable = appDAO.GetCHTMVPNByChgType(txtApplicant.Text, kind)
            PopupFormForAjax(btnUserPhone, "Serial,EmpNo,EmpName,UserPhone,UserIDNo,PnpCode,FirstPay", "編號,工號,姓名,手機,證件號碼,簡碼,群首付費", dt, hidbName.Value, "1,4", txtSerial.ClientID & "," & txtPhoneNo.ClientID, "directories=no,location=no,menubar=no,toolbar=no,scrollbars=yes, width800 ,left=200", "您需要選擇1筆你要的門號,請先按下要選的門號的[選取],此時資料列會變色,若確認無誤時再按下[確定離開]!")

        Catch ex As Exception

        End Try
      
    End Sub

    Protected Sub ddlModiItem_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlModiItem.SelectedIndexChanged
        txtSerial.Text = ""
        txtPhoneNo.Text = ""
        Try
            Dim appDAO As Telecom.DAO.ApplyDAO = New Telecom.DAO.ApplyDAO(hidbName.Value)
            Dim kind As String
            Dim modiAdo As Telecom.DAO.ModifyItemDAO = New Telecom.DAO.ModifyItemDAO(hidbName.Value)
            Dim dr As DataRow
            dr = modiAdo.GetModifyItem_Data(ddlSite.SelectedValue, ddlModiItem.SelectedValue).Rows(0)
            kind = dr("kind").ToString()
            If kind = "3" Then
                trMemo.Visible = True

            Else
                trMemo.Visible = False
            End If
            If kind = "2" Then
                txtPnpCodeNew.ReadOnly = False
                txtPnpCodeNew.CssClass = ""
            Else
                txtPnpCodeNew.ReadOnly = True
                txtPnpCodeNew.CssClass = "ReadOnly"
            End If

            If (dr("Message").ToString.Trim <> "") Then
                ShowMessageForAjax(btnUserPhone, dr("Message").ToString.Trim)
            End If

            Dim dt As DataTable = appDAO.GetCHTMVPNByChgType(txtApplicant.Text, kind)
            If dt.Rows.Count = 1 Then ''只有一筆時直接代入
                txtSerial.Text = dt.Rows(0)("Serial").ToString
                txtPhoneNo.Text = dt.Rows(0)("UserPhone").ToString
            ElseIf dt.Rows.Count = 0 Then
                ShowMessageForAjax(btnUserPhone, "無資料可選!")
                Exit Sub
            Else
                ' ShowMessageForAjax(btnUserPhone, "有2筆資料以上,所以您需要選擇1筆你要的門號,請先按下要選的門號的[選取],此時資料列會變色,若確認無誤時再按下[確定離開]!")
                PopupFormForAjax(btnUserPhone, "Serial,EmpNo,EmpName,UserPhone,UserIDNo,PnpCode,FirstPay", "編號,工號,姓名,手機,證件號碼,簡碼,群首付費", dt, hidbName.Value, "1,4", txtSerial.ClientID & "," & txtPhoneNo.ClientID, "directories=no,location=no,menubar=no,toolbar=no,scrollbars=yes, width800 ,left=200", "有2筆資料以上,所以您需要選擇1筆你要的門號,請先按下要選的門號的[選取],此時資料列會變色,若確認無誤時再按下[確定離開]!")



            End If

        Catch ex As Exception

        End Try
      
    End Sub

    
End Class
